package cn.example.fragmenttest3;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Fragment_line extends Fragment {

    public CallBackValue callBackValue;
    //定义一个回调接口
    public interface CallBackValue{
        public void SendMessageValue(String strValue);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        callBackValue= (CallBackValue) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1, container, false);
        TextView id = view.findViewById(R.id.tv_my);
        // 响应activity传递过来的数据
        Bundle bundle = getArguments();
        String o = (String) bundle.get("frag1");
        id.setText(o);
        //向activity发送数据
        callBackValue.SendMessageValue("fragment 发送来的数据");
        return view;
    }

}
